package com.huaru.message.scheduling;


import com.alibaba.fastjson.JSONObject;
import com.huaru.message.Vo.UsageRateVO;
import com.huaru.message.utile.Config;
import com.huaru.message.utile.CourseUtils;
import com.huaru.message.utile.SendMessageUtil;
import org.springframework.beans.factory.annotation.Value;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;

import static com.huaru.message.config.ReceiveMessage.PID;

public class CourseInfoThred extends Thread{

    @Override
    public void run() {
        while (true){
            UsageRateVO courseInfo = CourseUtils.getCourseInfo(PID);
            JSONObject jsonObject = new JSONObject();
            JSONObject data = new JSONObject();
            jsonObject.put("packType","CourseInfo");
            String hostAddress = null;
            try {
                hostAddress = InetAddress.getLocalHost().getHostAddress();
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
            data.put("ip",hostAddress);
            data.put("currentTime",new Date());
            data.put("courseInfo",courseInfo);
            jsonObject.put("data",data);
            String receiveAddress = Config.getString("receiveAddress");
            SendMessageUtil.Send(jsonObject,receiveAddress);
            try {
                sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
